﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HYI.SDBSERVER;

namespace SHRBIZE
{
    public partial class FMI_TC_SAFEINV : SDBSERVER.FMSINGLE
    {
        //入口函数
        public static Int32 StartMe(string sMainPara, string sPara, string sUser, DBSERVER sDB)
        {
            StaticClass.Selectm_MainPara = sMainPara;
            StaticClass.SelectItemValue = sPara;
            StaticClass.SelectUser = sUser;
            StaticClass.myDB = sDB;
            return 0;
        }

        private string sSite_No;
        //DBSERVER myADO = new DBSERVER();
        DBCache myCache = new DBCache();
        private int iGridView = 0;
        private int iGridView2 = 0;

        public FMI_TC_SAFEINV()
        {
            InitializeComponent();
        }

        //查询代码
        protected override void OnSys04()
        {
            string sParentNo = "";
            DataRowView dr1 = (DataRowView)cbfpoint_no.SelectedItem;
            if ((dr1 != null) && (cbfpoint_no.SelectedIndex > 0))
            {
                sParentNo = dr1.Row["fpoint_no"].ToString() ;
            }

            string sflayer_no = "";
            DataRowView dr2 = (DataRowView)cbflayer_no.SelectedItem;
            if ((dr2 != null) && (cbflayer_no.SelectedIndex > 0))
            {
                sflayer_no = dr2.Row["flayer_no"].ToString();
            }
            
            string SQL = "exec proc_cab_dogetsafeinv "
                + "'" + sParentNo + "'"
                + ",'" + sflayer_no + "'"
                + ",'" + uipoint.Tag.ToString() + "'"
                + ",'" + uibatchano.Text + "'"
                + ",1";
            Qrytable = StaticClass.myDB.query(SQL);

            base.OnSys04();
            rowindex = -1;
        }

        private void FMI_TC_SAFEINV_Load(object sender, EventArgs e)
        {
            sUser = StaticClass.SelectUser;
            string[] strArray = StaticClass.Selectm_MainPara.Split(new char[] { ';' });
            sMenu = strArray[1];
            sSite_No = strArray[0];

            //按钮控制
            sys01.Visible = false; sys01.Tag = "1";
            sys02.Visible = false; sys02.Tag = "1";
            sys03.Visible = false; sys03.Tag = "1";
            sys05.Visible = false; sys05.Tag = "1";
            sys07.Visible = false; sys07.Tag = "1";
            sys08.Visible = false; sys08.Tag = "1";
            sys09.Visible = false; sys09.Tag = "1";
            sys10.Visible = true; sys10.Text = "库存明细";
            sys11.Visible = false; sys11.Tag = "1";
            uipoint.Tag = "";

            //下拉框
            DataTable myTs_Dict = myCache.doGetDict("A_TS_POINT", "fpoint_flag=2");

            DataRow dr1 = myTs_Dict.NewRow();
            dr1["fpoint_name"] = "请选择";
            dr1["fpoint_no"] = "0";
            myTs_Dict.Rows.InsertAt(dr1, 0);
            cbfpoint_no.DataSource = myTs_Dict;
            cbfpoint_no.DisplayMember = "fpoint_name";
            cbfpoint_no.ValueMember = "fpoint_no";
            cbfpoint_no.SelectedIndex = 0;

            DataTable myTs_Layer = myCache.doGetDict("A_TS_LAYER", "");

            DataRow dr2 = myTs_Layer.NewRow();
            dr2["flayer_name"] = "请选择";
            dr2["flayer_no"] = "0";
            myTs_Layer.Rows.InsertAt(dr2, 0);
            cbflayer_no.DataSource = myTs_Layer;
            cbflayer_no.DisplayMember = "flayer_name";
            cbflayer_no.ValueMember = "flayer_no";
            cbflayer_no.SelectedIndex = 0;

            //执行查询代码
            OnSys04();

            //表格列显示统一控制
            if (iGridView == 0)
            {
                myCache.doSetGridVIew(sMenu, sUser, uiDGView);
                iGridView = iGridView + 1;
            }

        }

        private void uiBtn1_Click(object sender, EventArgs e)
        {
            //弹窗选择储物仓
            uipoint.Text = "";
            uipoint.Tag = "";

            string DATA = doPOPWINDOS("实验室查询"
                , "fpoint_no,实验室编号,121;fpoint_name,实验室名称,141"
                , " select fpoint_no,fpoint_name from a_ts_point where fpoint_flag = 0"
               , " order by fpoint_no"
                , 0);
            Console.WriteLine("当前返回:" + DATA);

            if ((DATA is null) || (DATA.Length == 0))
            {
                return;
            }
            string[] strArray = DATA.Split(',');

            uipoint.Text = strArray[1];
            uipoint.Tag = strArray[0];
            OnSys04();
        }

        private void cbfpoint_no_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }

        private void cbflayer_no_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iGridView > 0)
            {
                OnSys04();
            }
        }

        //查看库存明细
        protected override void OnSys10()
        {
            Console.WriteLine("行:" + rowindex.ToString());
            if (rowindex == -1)
            {
                return;
            }
            uifparent_name.Text = uiDGView["fparent_name", rowindex].Value.ToString();
            uiflayer_name.Text = uiDGView["flayer_name", rowindex].Value.ToString();
            uifpoint_name.Text = uiDGView["fpoint_name", rowindex].Value.ToString();
            uifcasno.Text = uiDGView["fcasno", rowindex].Value.ToString();
            uifgoodno.Text = uiDGView["fgoodno", rowindex].Value.ToString();
            uifgoodname.Text = uiDGView["fgoodname", rowindex].Value.ToString();

            string sParentNo= uiDGView["fparent_no", rowindex].Value.ToString();
            string sflayer_no = uiDGView["flayer_no", rowindex].Value.ToString();
            string sPoint_No = uiDGView["fpoint_no", rowindex].Value.ToString();

            string SQL = "exec proc_cab_dogetsafeinv "
                + "'" + sParentNo + "'"
                + ",'" + sflayer_no + "'"
                + ",'" + sPoint_No + "'"
                + ",'" + uifgoodno.Text + "'"
                + ",2";

            DataTable myDetail = StaticClass.myDB.query(SQL);
            uiDetail.DataSource = myDetail;

            base.OnSys10();

            //表格列显示统一控制
            if (iGridView2 == 0)
            {
                myCache.doSetGridVIew(sMenu + "1", sUser, uiDetail);
                iGridView2 = iGridView2 + 1;
            }
        }

        private void uiDetail_DoubleClick(object sender, EventArgs e)
        {
            string iMenu = sMenu + "1";
            OnGridDbClick(iMenu, uiDetail);
        }
    }
}
